﻿using System;
using System.ComponentModel.Composition;
using Cubicle.Core.Interfaces;

namespace Cubicle.Core.Processors.Invoke
{
    [Export("Cubicle.Processors.Invoke.CompletionProcessor", typeof(IProcessor<InstructionRequest>))]
    [ExportMetadata("Name", "CompletionProcessor")]
    [ExportMetadata("Description", "Marks requests as completed or failed")]
    public class CompletionProcessor : TryCatchProcessor<InstructionRequest>
    {

        public override InstructionRequest PreProcess(InstructionRequest input)
        {
            return input;
        }

        public override InstructionRequest PostProcess(InstructionRequest output)
        {
            output.Type(RequestType.Completed);
            return output;
        }

        public override InstructionRequest OnException(Exception ex, InstructionRequest input)
        {
            input.Type(RequestType.Failed);
            return input;
        }

    }
}